﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
//using CSVReader;

namespace CSVReader.Test
{
    [TestFixture]
    public class TestCsvReader
    {
        [Test]
        public void Fehlender_Dateiname_liefert_null()
        {
            string s;

            s = null;
            IEnumerable<string[]> result = ReadController.ReadCSVFile(s);
            Assert.That(result, Is.EqualTo(null));

            s = "";
            result = ReadController.ReadCSVFile(s);
            Assert.That(result, Is.EqualTo(null));

        }

        [Test]
        public void Gibt_Zeilen_zurück_Eine_beliebige_muss_mit_Ergebnis_uebereinstimmen()
        {
            IEnumerable<string[]> result = ReadController.ReadCSVFile("Personen.csv");
            string[] sArray = result.First();
            Assert.That(sArray, Is.EqualTo(new[] { "Lieser", "Stefan", "Trainer" }));
            sArray = result.ElementAt(1);
            Assert.That(sArray, Is.EqualTo(new[] { "Westphal", "Ralf", "Coach" }));
        }
    }

    [TestFixture]
    public class TestSplitLine
    {
        [Test]
        public void Zeile_ist_leer()
        {
            Assert.That(ReadController.SplitLine(string.Empty), Is.EqualTo(new string[0]));
        }

        [Test]
        public void Zeile_enthaelt_Leerfelder()
        {
            Assert.That(ReadController.SplitLine("Lieser;;Trainer").Length, Is.EqualTo(2));
        }

        [Test]
        public void Zeile_enthaelt_nicht_genau_drei_Felder()
        {
            //Wie prüfe ich, ob die geprüfte Klasse den richtigen Fehler auswirft?
            //Assert.That(ReadController.SplitLine("Lieser;;Trainer"), Is.EqualTo(null));
            Assert.Throws<ArgumentException>(() => ReadController.SplitLine("Lieser;;Coach"));
        }

        [Test]
        public void Zeile_enthält_drei_Felder_und_Werte_stimmen()
        {
            Assert.That(ReadController.SplitLine("Lieser;Stefan;Trainer"),
                        Is.EqualTo(new[] {"Lieser", "Stefan", "Trainer"}));
        }
    }

    [TestFixture]
    public class  TestReadFile
    {
        [Test]
        public void Datei_ist_nicht_vorhanden()
        {
            var result = ReadController.ReadFile("test");
            Assert.That(result, Is.EqualTo(null));
        }

        [Test]
        public void Datei_ist_vorhanden()
        {
            var result = ReadController.ReadFile("Personen.csv");
            Assert.That(result.Length, Is.EqualTo(3));
            
        }

    }
}
